package Day3;
import java.util.ArrayList;
import java.util.Scanner;

public class Mangerstudent {
    static ArrayList<Student> list=new ArrayList<>();
    public static void main(String[] args) {
        boolean isFinish=true;
        while (isFinish) {
            System.out.println("--------------欢迎来到学生管理系统--------------");
            System.out.print("1 添加学生" + "\t");
            System.out.print("2 删除学生" + "\t");
            System.out.print("3 修改学生" + "\t");
            System.out.print("4" + "查看" + "\t");
            System.out.println("5 退出");
            System.out.println("请选择功能-----");
            Scanner scanner = new Scanner(System.in);
            int actionNumber = scanner.nextInt();
            switch (actionNumber) {
                case 1:
                    System.out.print("添加学生");
                    addStudent();
                    break;
                case 2:
                    System.out.print("删除学生");
                    deleteStudent();
                    break;
                case 3:
                    System.out.print("修改学生");
                    updateStudent();
                    break;
                case 4:
                    System.out.println("查看");
                    getStudentInfo();
                    break;
                case 5:
                    System.out.print("退出");
                    isFinish=false;
                    break;
            }
        }
    }
    private static void addStudent () {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入学号：");
        String id = scanner.nextLine();
        System.out.println("请输入姓名：");
        String name = scanner.nextLine();
        System.out.println("请输入电话：");
        String phoneNumber = scanner.nextLine();
        System.out.println("请输入年龄：");
        int age = scanner.nextInt();

        Student student = new Student(id, name, age, phoneNumber);
        list.add(student);
        System.out.println("添加成功");

    }
    private static void getStudentInfo() {
        for (int i = 0; i < list.size(); i++) {
            Student student = list.get(i);
            System.out.println(student.getIdNumber() + "\t" + student.getName() + "\t" + student.getAge() + "\t" + student.getPhoneNm());
        }

    }
    public static void deleteStudent(){
        System.out.println("请输入删除学生的学号：");
        Scanner scanner=new Scanner(System.in);
        String id=scanner.nextLine();
        boolean inSuccess=false;
        for (int i = 0; i < list.size(); i++) {
            Student student=list.get(i);
            if (id.equals(student.getIdNumber())){
                list.remove(i);
                System.out.println("删除成功");
                inSuccess=true;
                break;
            }
        }
        if (!inSuccess){
            System.out.println("没有此人");
        }
    }
    private static void updateStudent(){
        System.out.println("输入学生的学号:");
        Scanner scanner=new Scanner(System.in);
        String id=scanner.nextLine();
        for (int i = 0; i < list.size(); i++) {
            Student student=list.get(i);
            if (id.equals(student.getIdNumber())){
                System.out.println("请输入新的姓名：");
                String newName=scanner.nextLine();
                System.out.println("请输入新的电话：");
                String newPhoneNumber=scanner.nextLine();
                System.out.println("请输入新的年龄：");
                int  newAge=scanner.nextInt();
                student.setName(newName);
                student.setPhoneNm(newPhoneNumber);
                student.setAge(newAge);
                list.set(i,student);
            }else {
                System.out.println("错误信息");
            }
        }

    }
}


